# 作者: 肖老师
# 2024年11月12日07时21分08秒
# xxxrlmk@163.com
from attr.validators import instance_of

xiaoming_dict = {"name": "小明"}

# 1. 取值
print(xiaoming_dict['name'])  # keyerror 不存在对应的键

# 2. 增加/修改
# 如果key不存在，会新增键值对
xiaoming_dict["age"] = 18
# 如果key存在，会修改已经存在的键值对
xiaoming_dict['name'] = '小小明'
print(xiaoming_dict)
# 3. 删除
xiaoming_dict.pop("name")
print(xiaoming_dict)

# 4. 统计键值对数量
print(len(xiaoming_dict))

# 5 合并字典
temp_dict = {"height": 1.75,
             "age": 20}

xiaoming_dict.update(temp_dict)

print(xiaoming_dict)

# 6. 清空字典
xiaoming_dict.clear()

print(xiaoming_dict)

my_dict = {}  # 空字典

xiaoming_dict = {"name": "小明",
                 "qq": 123456,
                 "phone": "10086"}
# 迭代遍历字典
# 变量k是每一次循环中，获取到的键值对的key
for k in xiaoming_dict:
    print(f'{k}---{xiaoming_dict[k]}')
"""
此种遍历仅会取出键值
for i in xiaoming_dict:
    print(i)
"""

for k in xiaoming_dict.items():  # items是把键值对组合为一个元组
    print(k)

print('-' * 50)
card_list = [
    {"name": "张三",
     "qq": "12345",
     "phone": "110"},
    {"name": "李四",
     "qq": "54321",
     "phone": "10086"}
]

for card_info in card_list:
    print(card_info)

empty_dict = {}
# empty_dict=dict()

if __name__ == '__main__':
    a1 = ['1','2','3']
    a2 = '1','2','3'
    a3 = {'1','2','3'}
    a4 = {'aa':'11','bb':'22','cc':'33'}
    print(type(a1))
    print(type(a2))
    print(type(a3))
    print(type(a4))
    print(a4.get("bb"))
    print(a3)